var ctx=window.daijia.ctx;
$(function () {
	
	$("#code").qrcode({
		render: "canvas", //table方式
		width: 145, //宽度
		height:145, //高度
		text: "http://app.daijia.wang/apps/boss/"+$("#code").attr("web-url")+".html" //任意内容
	});

	$.post(ctx+'/boss/getReportingData',{},function(data){
		$("#todayMember").text(data.todayMember);
		$("#todayOrderCount").text(data.todayOrderCount);
		$("#todayOrderCash").text(data.todayOrderCash);
	
		$("#yestodayMember").text(data.yestodayMember);
		$("#yestodayOrderCount").text(data.yestodayOrderCount);
		$("#yestodayOrderCash").text(data.yestodayOrderCash);
		
		if(data.yesterdayWarms>0){
			$("#yesterdayWarms").html("<font color='red'>"+data.yesterdayWarms+"</font>");
		}
		else{
			$("#yesterdayWarms").html(data.yesterdayWarms);
		}
		
		if(data.lastWeekWarms>0){
			$("#lastWeekWarms").html("<font color='red'>"+data.lastWeekWarms+"</font>");
		}
		else{
			$("#lastWeekWarms").html(data.lastWeekWarms);
		}
		
		if(data.lastMonthWarms>0){
			$("#lastMonthWarms").html("<font color='red'>"+data.lastMonthWarms+"</font>");
		}
		else{
			$("#lastMonthWarms").html(data.lastMonthWarms);
		}
		
		new Highcharts.Chart({
			 chart : {
		      renderTo : 'userChart'
		     },
	         title: {
	             text: '新增用户走势图',
	             x: -20
	         },
	         subtitle: {
	             text: '最近一周内的新增用户走势',
	             x: -20
	         },
	         xAxis: {
	             categories: data.dateList.reverse()
	         },
	         yAxis: {
	             title: {
	                 text: '人数'
	             },
	             plotLines: [{
	                 value: 0,
	                 width: 1,
	                 color: '#808080'
	             }]
	         },
	         tooltip: {
	             valueSuffix: '人'
	         },
	         series: [{
	             name: '新增用户',
	             data: data.memberCountList.reverse()
	         }]
	    });
	    
	    new Highcharts.Chart({
			 chart : {
		      renderTo : 'orderChart'
		     },
	         title: {
	             text: '下单走势图',
	             x: -20
	         },
	         subtitle: {
	             text: '最近一周内的下单走势',
	             x: -20
	         },
	         xAxis: {
	             categories: data.dateList
	         },
	         yAxis: {
	             title: {
	                 text: '单量'
	             },
	             plotLines: [{
	                 value: 0,
	                 width: 1,
	                 color: '#808080'
	             }]
	         },
	         tooltip: {
	             valueSuffix: '单'
	         },
	         series: [{
	             name: '总单量',
	             data: data.orderCountList.reverse()
	         },{
	             name: '销单量',
	             data: data.orderCancelCountList.reverse()
	         }]
	    });
	    
	    new Highcharts.Chart({
			 chart : {
		      renderTo : 'cashChart'
		     },
	         title: {
	             text: '收入走势图',
	             x: -20
	         },
	         subtitle: {
	             text: '最近一周内的收入走势',
	             x: -20
	         },
	         xAxis: {
	             categories: data.dateList
	         },
	         yAxis: {
	             title: {
	                 text: '收入'
	             },
	             plotLines: [{
	                 value: 0,
	                 width: 1,
	                 color: '#808080'
	             }]
	         },
	         tooltip: {
	             valueSuffix: '元'
	         },
	         series: [{
	             name: '总收入',
	             data: data.orderCashList.reverse()
	         }]
	    });
	    
	});
	
});


function dateFormat(date,fmt){

	  var o = {   
	    "M+" : date.getMonth()+1,                 //月份   
	    "d+" : date.getDate(),                    //日   
	    "h+" : date.getHours(),                   //小时   
	    "m+" : date.getMinutes(),                 //分   
	    "s+" : date.getSeconds(),                 //秒   
	    "q+" : Math.floor((date.getMonth()+3)/3), //季度   
	    "S"  : date.getMilliseconds()             //毫秒   
	  };   
	  if(/(y+)/.test(fmt))   
	    fmt=fmt.replace(RegExp.$1, (date.getFullYear()+"").substr(4 - RegExp.$1.length));   
	  for(var k in o)   
	    if(new RegExp("("+ k +")").test(fmt))   
	  fmt = fmt.replace(RegExp.$1, (RegExp.$1.length==1) ? (o[k]) : (("00"+ o[k]).substr((""+ o[k]).length)));   
	  return fmt;   

}
